package com.legal.aid.app.controller;

import com.legal.aid.app.domain.dto.CollectDto;
import com.legal.aid.app.service.IAppCollectService;
import com.legal.aid.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.legal.aid.common.core.domain.AjaxResult.success;

@RestController
@RequestMapping("/app/collect")
public class AppCollectController {

    @Autowired
    private IAppCollectService appCollectService;

    /**
     * 检查收藏状态
     */
    @GetMapping("/status")
    public AjaxResult checkStatus(@RequestParam Long targetId, @RequestParam String targetType) {
        System.out.println("AppCollectController - checkStatus: targetId=" + targetId + ", targetType=" + targetType);
        return success(appCollectService.checkStatus(targetId, targetType));
    }

    /**
     * 添加收藏
     */
    @PostMapping
    public AjaxResult addCollect(@RequestBody CollectDto collectDto) {
        System.out.println("AppCollectController - addCollect: " + collectDto);
        return success(appCollectService.add(collectDto));
    }

    /**
     * 取消收藏
     */
    @PutMapping
    public AjaxResult cancelCollect(@RequestBody CollectDto collectDto) {
        System.out.println("AppCollectController - cancelCollect: " + collectDto);
        return success(appCollectService.cancel(collectDto));
    }

    /**
     * 切换收藏状态
     */
    @PostMapping("/toggle")
    public AjaxResult toggleCollect(@RequestBody CollectDto collectDto) {
        System.out.println("AppCollectController - toggleCollect: " + collectDto);
        return success(appCollectService.toggle(collectDto));
    }
}
